import time,Process,shutil,os,sys

def startClient(clientIP, expId, turn, factor):
    serverIP = "192.168.0.1"
    cmd = "ssh -i ~/.ssh/sqid -l sq " + clientIP + " 'cd OpenTTDTesting; cd src; nohup client.sh " + serverIP + " %d"%expId
    cmd = cmd + " %d"%turn + " %d"%factor + " %d"%Process.maxYear + " " + clientIP + "'"
    print cmd
#    os.system("ssh " + clientIp + "")
#    if(sys.platform == "win32"):    
#        os.system("test1c.bat") 
#    elif sys.platform.find("linux") >= 0 :
#        os.system("openttd -g -n 127.0.0.1:3979&")
#    print "start fake client " + clientIP
    return True

clients = ["127.0.0.1", "127.0.0.2"]
if __name__ == "__main__":
    clientIp = "192.168.0.100"
    expId = 29
    cmd = "scp -i ~/.ssh/sqid -r sq@"+clientIp + ":~/OpenTTDTesting/test_result/1c/analysis/%d"%expId + "* ~/file/"
    if sys.platform == "win32":
        path = "c:\\cygwin\\home\\Q\\startclient.sh"
        f = open(path, "w")
        print >> f, cmd
        f.close()
        print cmd
    os.system("startClient.bat")
    src = "c:/cygwin/home/Q/file"
    dest = os.path.join("..", "test_result", "1c", "analysis")
    dest2 = os.path.join("..", "test_result", "trunk")
    for file in os.listdir(src):
        source = src + "/" + file
        shutil.copy(source, dest)
        shutil.copy(source, dest2)

